Ubuntu 16.04
Sponsored Link

Nginx : Basic Authentication
2016/07/07
 
Enable Basic Authentication to limit access on specific web pages.
[1] For example, set Basic Auth under the "/auth-basic" directory.
root@www:~#
apt-get -y install apache2-utils
root@www:~#
vi /etc/nginx/sites-available/default
# add into "server" section

        location /auth-basic {
            auth_basic            "Basic Auth";
            auth_basic_user_file  "/etc/nginx/.htpasswd";
        }

root@www:~#
htpasswd -c /etc/nginx/.htpasswd ubuntu

New password:    
# set password

Re-type new password:
Adding password for user ubuntu
root@www:~#
mkdir /var/www/html/auth-basic

root@www:~#
systemctl restart nginx
[2] Access to the test page with Web browser on a Client and authenticate with a user which is added with htpasswd.
[3] Just accessed.
 
Tweet